<template>
  <el-card class="blog-card" shadow="hover" @click="goToDetail">
    <div class="blog-card-image" v-if="post.coverImage">
      <img :src="post.coverImage" alt="文章封面">
      <div class="blog-card-tag" v-if="post.isTop">置顶</div>
    </div>
    <div class="blog-card-content">
      <div class="blog-card-tags">
        <el-tag v-for="tag in post.tags" :key="tag" size="small" class="blog-tag" effect="plain">{{ tag }}</el-tag>
      </div>
      <h3 class="blog-card-title">{{ post.title }}</h3>
      <p class="blog-card-desc">{{ post.description }}</p>
      <div class="blog-card-meta">
        <span class="blog-card-date">
          <el-icon><Calendar /></el-icon> {{ post.date }}
        </span>
        <span class="blog-card-views">
          <el-icon><View /></el-icon> {{ post.views }}次浏览
        </span>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { Calendar, View } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const props = defineProps({
  post: {
    type: Object,
    required: true
  }
})

const goToDetail = () => {
  router.push(`/articles/${props.post.id}`)
}
</script>

<style scoped>
.blog-card {
  margin-bottom: 24px;
  transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  height: 100%;
  display: flex;
  flex-direction: column;
  z-index: 1;
  cursor: pointer;
  border: 1px solid #f0f0f0;
  border-radius: 2px;
  background-color: #fff;
}

.blog-card:hover {
  transform: translateY(-2px);
  z-index: 2;
  box-shadow: 0 1px 2px -2px rgba(0, 0, 0, 0.16), 
              0 3px 6px 0 rgba(0, 0, 0, 0.12), 
              0 5px 12px 4px rgba(0, 0, 0, 0.09);
}

.blog-card :deep(.el-card__body) {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.blog-card-image {
  position: relative;
  height: 180px;
  overflow: hidden;
  border-radius: 2px 2px 0 0;
}

.blog-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.blog-card:hover .blog-card-image img {
  transform: scale(1.05);
}

.blog-card-tag {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 8px;
  background-color: var(--accent-color);
  color: #fff;
  font-size: 12px;
  border-radius: 2px;
}

.blog-card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px 24px;
}

.blog-card-tags {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.blog-tag {
  margin: 0;
}

.blog-card-title {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 12px;
  color: rgba(0, 0, 0, 0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5715;
}

.blog-card-desc {
  color: rgba(0, 0, 0, 0.45);
  font-size: 14px;
  margin: 0 0 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  line-height: 1.5715;
}

.blog-card-meta {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

.blog-card-date, .blog-card-views {
  display: flex;
  align-items: center;
  gap: 4px;
}
</style>
